home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FONT_SIZ.C < prev    next >
Text File  |  1989-02-09  |  10KB  |  391 lines

  1. /************************************************************************
  2.  
  3.             font_size_stylemenu.c
  4.  
  5.             For LightspeedC 2.15
  6.             Apple Macintosh System Version 6.0
  7.  
  8.             07/04/88
  9.             GALEN B. BABCOCK
  10.             1932 N. TURQUOISE
  11.             WICHITA, KANSAS 67212
  12.             316-721-1226
  13.  
  14.                  GEnie:    G.BABCOCK
  15.             CompuServe:    74666,2457
  16.  
  17.             Font, Size, and Style menu utilities
  18.  
  19.             CONTAINS
  20.             ------------------------------------------------------
  21.             outline_real_fonts()
  22.             check_style_menu()
  23.             check_font_name()
  24.             check_font_size()
  25.             select_style_menu()
  26.             select_size_menu()
  27.             select_font_menu()
  28.             ------------------------------------------------------
  29.  
  30.             ---- Revisions ----
  31.             AUTHOR    DESCRIPTION
  32.             ------    ----------------------------------------------------
  33.  
  34. ************************************************************************/
  35.  
  36. #include <QuickDraw.h>
  37. #include <MenuMgr.h>
  38.  
  39. #define    PlainItem        1
  40. #define    BoldItem        2
  41. #define ItalicItem        3
  42. #define    UnderlineItem    4
  43. #define OutlineItem        5
  44. #define    ShadowItem        6
  45. #define CondenseItem    7
  46. #define ExtendItem        8
  47.  
  48. /************************************************************************
  49.  
  50.     The font_size_stylemenu.c routines expect the Style menu to be
  51.     set up in the following order...
  52.  
  53.             Plain
  54.             Bold
  55.             Italic
  56.             Underline
  57.             Outline
  58.             Shadow
  59.             Condense
  60.             Extend
  61.  
  62.     For routines which accept a "begin" and "length" parameters (int),
  63.     it is assumed that the related menu items start at the "begin"-th item
  64.     in the menu, and continue for "length" number of items.  For example,
  65.     the following menu of font sizes and styles are contained in the
  66.     same menu.  To use font size routines, you would pass "1" in the "begin"
  67.     parameter, and "7" in the "length" parameter, and for routines that
  68.     deal with font styles, pass "9" as the "begin" parameter, and "8" as
  69.     the "length" parameter.
  70.  
  71.             9            <-    begin = 1
  72.             10
  73.             12
  74.             14
  75.             18
  76.             24
  77.             36            <- length = 7
  78.             ------
  79.             Plain        <- begin = 9
  80.             Bold
  81.             Italic
  82.             Underline
  83.             Outline
  84.             Shadow
  85.             Condense
  86.             Extend        <- length = 8
  87.  
  88. ************************************************************************/
  89.  
  90. /*
  91.  
  92. =========================================================================
  93. [                                                                        ]
  94. [    check_style_menu()                                                    ]
  95. [                                                                        ]
  96. [    Places check marks beside the menu item style descriptors which        ]
  97. [    are contained in the style passed in "theStyle"                        ]
  98. [                                                                        ]
  99. =========================================================================
  100.  
  101. */
  102.  
  103. check_style_menu(theMenu,theStyle,begin,length)
  104.  
  105. MenuHandle        theMenu;            /*    the Style Menu                    */
  106. char            theStyle;            /*    Style to reflect in menu        */
  107. int                begin;                /*    location of "Plain" item        */
  108. int                length;                /*    number of style items            */
  109.  
  110. {
  111.     int            limit;
  112.     int            index;
  113.     int            bitPos;
  114.  
  115.     limit = begin+length-1;
  116.     if (theStyle == 0){
  117.         CheckItem(theMenu,begin,TRUE);
  118.         for (index=begin+1;index<=limit;index++)
  119.             CheckItem(theMenu,index,FALSE);
  120.     }
  121.     else{
  122.         CheckItem(theMenu,begin,FALSE);
  123.         /*
  124.         
  125.         NOTE
  126.         ===========================================================
  127.                         Bit Pattern             BitTst        Menu
  128.         Style            0 1 2 3 4 5 6 7        Position    Item
  129.         ------------    ---------------        --------    ----
  130.         bold = 1,        0 0 0 0 0 0 0 1            7          2
  131.         italic = 2,        0 0 0 0 0 0 1 0            6          3
  132.         underline = 4,    0 0 0 0 0 1 0 0            5          4
  133.         outline = 8,    0 0 0 0 1 0 0 0            4          5
  134.         shadow = 16,    0 0 0 1 0 0 0 0            3          6
  135.         condense = 32,    0 0 1 0 0 0 0 0            2          7
  136.         extend = 64        0 1 0 0 0 0 0 0            1          8
  137.         ===========================================================
  138.  
  139.         Since the Styles are bit positions, we can cycle through
  140.         testing each bit position, which correlates to a Style
  141.         being enabled or disabled.
  142.         
  143.         In this routine, we start with the lease significant bit,
  144.         
  145.         0      1      2     3    4    5    6    7
  146.                                    ---
  147.                         
  148.         which corresponds to the Bold style, or the 2nd item in
  149.         the style menu, then proceed to the 6th bit, 3rd item,
  150.         7th bit, 4th item, etc.
  151.         
  152.         For each bit position, we can calculate the menu item,
  153.         relative to the "begin" menu item, using:
  154.         
  155.         menuitem = begin + 8 - bitPos
  156.         
  157.         */
  158.         
  159.         for (index=begin,bitPos=7;index<limit;index++,bitPos--){
  160.             if (BitTst(&theStyle,bitPos) == TRUE)
  161.                 CheckItem(theMenu,begin+8-bitPos,TRUE);
  162.             else
  163.                 CheckItem(theMenu,begin+8-bitPos,FALSE);
  164.         }
  165.     }
  166. }
  167.  
  168. /*
  169.  
  170. =========================================================================
  171. [                                                                        ]
  172. [    select_style_menu()                                                    ]
  173. [                                                                        ]
  174. [    Changes theStyle (char *) according to theItem selected from the    ]
  175. [    Style menu.  If condense is selected, extend is deselected,            ]
  176. [    and vice versa, since having both selected simultaneously makes        ]
  177. [    no sense.                                                            ]
  178. [                                                                        ]
  179. =========================================================================
  180.  
  181. */
  182.  
  183. select_style_menu(theMenu,theItem,begin,length,theStyle)
  184.  
  185. MenuHandle        theMenu;        /*    the style menu                        */
  186. int                theItem;        /*    item selected from the menu            */
  187. int                begin;            /*    menu item of the "Plain" style item    */
  188. int                length;            /*    number of style items                */
  189. char            *theStyle;        /*    the style to change                    */
  190.  
  191. {
  192.     switch (theItem-begin+1){
  193.         case PlainItem:            *theStyle = 0;
  194.                                 break;
  195.         case BoldItem:            *theStyle ^= bold;
  196.                                 break;
  197.         case ItalicItem:        *theStyle ^= italic;
  198.                                 break;
  199.         case UnderlineItem:        *theStyle ^= underline;
  200.                                 break;
  201.         case OutlineItem:        *theStyle ^= outline;
  202.                                 break;
  203.         case ShadowItem:        *theStyle ^= shadow;
  204.                                 break;
  205.         case CondenseItem:        *theStyle ^= condense;
  206.                                 *theStyle &= (0XFF-extend);
  207.                                 break;
  208.         case ExtendItem:        *theStyle ^= extend;
  209.                                 *theStyle &= (0XFF-condense);
  210.                                 break;
  211.         default:                break;
  212.     }
  213. }
  214.  
  215. /*
  216.  
  217. =========================================================================
  218. [                                                                        ]
  219. [    outline_real_fonts()                                                ]
  220. [                                                                        ]
  221. [    Given the font number in theFont, this function outlines the        ]
  222. [    font sizes in the font size menu for which there is a defined        ]
  223. [    font resource for that size.  All font sizes which have to be        ]
  224. [    scaled are drawn in plain style.                                    ]
  225. [                                                                        ]
  226. =========================================================================
  227.  
  228. */
  229.  
  230. outline_real_fonts(theMenu,begin,length,theFont)
  231.  
  232. MenuHandle        theMenu;            /*    font size menu                    */
  233. int                begin;                /*    first font size item            */
  234. int                length;                /*    number of font size items        */
  235. int                theFont;            /*    which font                        */
  236.  
  237. {
  238.     int            limit;
  239.     int            index;
  240.     Str255        mString;
  241.     long        mNum;
  242.  
  243.     limit = begin+length-1;
  244.     for(index=begin;index<=limit;index++){
  245.         GetItem(theMenu,index,mString);
  246.         StringToNum(mString,&mNum);
  247.         if (RealFont(theFont,(int)mNum))
  248.             SetItemStyle(theMenu,index,outline);
  249.         else
  250.             SetItemStyle(theMenu,index,0);
  251.     }
  252. }
  253.  
  254. /*
  255.  
  256. =========================================================================
  257. [                                                                        ]
  258. [    check_font_name()                                                    ]
  259. [                                                                        ]
  260. [    For the font in "theFont", finds the name of the font in the        ]
  261. [    Font menu "theMenu", and places a check mark beside it, and            ]
  262. [    removes check marks from all other menu items.                        ]
  263. [                                                                        ]
  264. =========================================================================
  265.  
  266. */
  267.  
  268. check_font_name(theMenu,theFont)
  269.  
  270. MenuHandle        theMenu;        /*    Font Menu                            */
  271. int                theFont;        /*    font number to check mark            */
  272.  
  273. {
  274.     int            index,limit;
  275.     Str255        fStr,mStr;
  276.  
  277.     GetFontName(theFont,fStr);
  278.     PtoCstr((char *)fStr);
  279.  
  280.     limit = CountMItems(theMenu);
  281.     for(index=1;index<=limit;index++){
  282.         GetItem(theMenu,index,mStr);
  283.         PtoCstr((char *)mStr);
  284.         if (strcmp(mStr,fStr) == 0)
  285.             CheckItem(theMenu,index,TRUE);
  286.         else
  287.             CheckItem(theMenu,index,FALSE);
  288.     }
  289. }
  290.  
  291. /*
  292.  
  293. =========================================================================
  294. [                                                                        ]
  295. [    check_font_size()                                                    ]
  296. [                                                                        ]
  297. [    Places a checkmark beside the font size menu item passed in            ]
  298. [    "theSize", removes check marks from all other menu items.            ]
  299. [                                                                        ]
  300. =========================================================================
  301.  
  302. */
  303.  
  304. check_font_size(theMenu,begin,length,theSize)
  305.  
  306. MenuHandle        theMenu;    /*    font Size menu                            */
  307. int                begin;        /*    first Size item in the menu                */
  308. int                length;        /*    number of Size items                    */
  309. int                theSize;    /*    the size to check mark                    */
  310.  
  311. {
  312.     int            index;
  313.     int            limit;
  314.     Str255        mStr;
  315.     long        mVal;
  316.  
  317.     limit = begin+length-1;
  318.     for(index=begin;index<=limit;index++){
  319.         GetItem(theMenu,index,mStr);
  320.         StringToNum(mStr,&mVal);
  321.         if ((int)mVal == theSize)
  322.             CheckItem(theMenu,index,TRUE);
  323.         else
  324.             CheckItem(theMenu,index,FALSE);
  325.     }
  326. }
  327.  
  328.  
  329. /*
  330.  
  331. =========================================================================
  332. [                                                                        ]
  333. [    select_size_menu()                                                    ]
  334. [                                                                        ]
  335. [    Changes the text font size "theSize" (int *) to the size selected    ]
  336. [    from "theMenu" font size menu.  Places a checkmark beside the size    ]
  337. [    selected, and removes checks from all other items                    ]
  338. [                                                                        ]
  339. =========================================================================
  340.  
  341. */
  342.  
  343. select_size_menu(theMenu,theItem,begin,length,theSize)
  344.  
  345. MenuHandle        theMenu;        /*    the font size menu                    */
  346. int                theItem;        /*    item selected                        */
  347. int                begin;            /*    first font size item                */
  348. int                length;            /*    number of font size items            */
  349. int                *theSize;        /*    change to font selected font size    */
  350.  
  351. {
  352.     int            limit;
  353.     int            index;
  354.     Str255        mStr;
  355.     long        mVal;
  356.  
  357.     limit = begin+length-1;
  358.     for(index=begin;index<=limit;index++)
  359.         CheckItem(theMenu,index,FALSE);
  360.     CheckItem(theMenu,theItem,TRUE);
  361.     GetItem(theMenu,theItem,mStr);
  362.     StringToNum(mStr,&mVal);
  363.     *theSize = (int)mVal;
  364. }
  365.  
  366. /*
  367.  
  368. =========================================================================
  369. [                                                                        ]
  370. [    select_font_menu()                                                    ]
  371. [                                                                        ]
  372. [    Changes the text font "theFont" (int *) to the font selected        ]
  373. [    from "theMenu" font menu.  Places a checkmark beside the font        ]
  374. [    selected, and removes checks from all other items.                    ]
  375. [                                                                        ]
  376. =========================================================================
  377.  
  378. */
  379.  
  380. select_font_menu(theMenu,theItem,theFont)
  381.  
  382. MenuHandle        theMenu;        /*    Font menu                            */
  383. int                theItem;        /*    item selected                        */
  384. int                *theFont;        /*    place for the new font number        */
  385.  
  386. {
  387.     Str255            fnName;
  388.  
  389.     GetItem(theMenu,theItem,fnName);
  390.     GetFNum(fnName,theFont);
  391. }